import { defineStore } from "pinia";
import { reactive } from "vue";
import type { RouteLocationNormalizedLoadedGeneric, RouteRecordRaw } from "vue-router";
import exprodRouter from '../router/stuteRouter'
const useRouterStore = defineStore('router', () => {
    let menuList: Array<RouteRecordRaw> = reactive(exprodRouter)
    let navTabs: Array<RouteLocationNormalizedLoadedGeneric> = reactive([])


    const addMenuList = (menuItem: RouteRecordRaw) => {
        menuList.push(menuItem)
    }

    function addTabItem(menuItem: RouteLocationNormalizedLoadedGeneric) {
        if (!navTabs.some(i => i.path === menuItem.path)) {
            navTabs.push(Object.assign({}, menuItem, { title: menuItem.meta.title }))
        }

    }
    function removeTabItem(menuItem: RouteLocationNormalizedLoadedGeneric) {
        console.log(menuItem)
        // navTabs = navTabs.filter(i => i.path !== menuItem.path)
        navTabs.forEach((i, index) => {
            if (i.path === menuItem.path) {
                navTabs.splice(index, 1)
            }
        })
        console.log(navTabs)
    }
    function removeOtherTab(menuItem: any) {
        navTabs = navTabs.filter(i => i.path === menuItem.path)
    }


    return {
        menuList,
        navTabs,
        addMenuList,
        addTabItem,
        removeTabItem,
        removeOtherTab

    }
})
export default useRouterStore